<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/web/header.jsp" %>
<title>添加商品信息</title>
</head>
<body>
<fieldset class="layui-elem-field" style="margin:30px;padding:30px">
	<legend>添加商品信息</legend>
	<div class="layui-field-box">
			<form class="layui-form-pane layui-form">
				<div class="layui-form-item">
				<label class="layui-form-label">一级分类</label>
					<div class="layui-input-inline">
						<select name="productType1" lay-verify="required" lay-search lay-filter="productType1"></select>
					</div>
				</div>
				
				<div class="layui-form-item">
				<label class="layui-form-label">二级分类</label>
					<div class="layui-input-inline">
						<select name="parentCode" lay-verify="required" lay-search></select>
					</div>
				</div>		
					
				<div class="layui-form-item">
					<label class="layui-form-label">商品编号</label>
					<div class="layui-input-inline">
						<input class="layui-input" name="code" type="text" placeholder="请输入商品编号"
						required lay-verify="required" autocomplete="off">
					</div>
				</div>
				
				<div class="layui-form-item">
					<label class="layui-form-label">商品名称</label>
					<div class="layui-input-inline">
						<input class="layui-input" name="name" type="text" placeholder="请输入商品名称"
						required lay-verify="required" autocomplete="off">
					</div>
				</div>
				
				<div class="layui-form-item">
					<label class="layui-form-label">商品单价</label>
					<div class="layui-input-inline">
						<input class="layui-input" name="price" type="text" placeholder="请输入商品单价"
						required lay-verify="required" autocomplete="off">
					</div>
				</div>
				
				<div class="layui-form-item">
					<label class="layui-form-label">状态</label>
					<div class="layui-input-inline">
						<select name="status" lay-verify="status">
							<option value="1">上架</option>
							<option value="0">下架</option>
						</select>
					</div>
				</div>
				
				<div class="layui-form-item">
					<label class="layui-form-label">商品描述</label>
					<div class="layui-input-inline">
						<input class="layui-input" name="descr" type="text" placeholder="请输入商品描述"
						required lay-verify="required" autocomplete="off">
					</div>
				</div>
				
				<div class="layui-form-item">
					<label class="layui-form-label">进货量</label>
					<div class="layui-input-inline">
						<input class="layui-input" name="inve" type="text" placeholder="请输入进货量"
						required lay-verify="required" autocomplete="off">
					</div>
				</div>
				
				
				
				<div class="layui-form-item">
					<div class="layui-input-inline">
						<input type="button" value="确定" class="layui-btn" lay-submit lay-filter="add"  />
						<input type="reset" value="重置" class="layui-btn layui-btn-primary" />
					</div>
				</div>
			</form>
		</div>
		
	</fieldset>

	<script type="text/javascript">
		getSelect('productType1','type1');
		function getSelect(selectid,parentCode){
			if(parentCode==''){
				$("select").empty();
				form.render("select");
				return;
			}
			ajax({parentCode:parentCode},'/cate/getAll.do','json',function(data){
				var html = "<option value=''>-- 请选择 --</option>";
				$.each(data,function(i,dom){
					html += "<option value='"+dom.code+"'>"+dom.name+"</option>"
				});
				$("select[name='"+selectid+"']").html(html);
				form.render('select');
			})
		}
	
		form.on('select(productType1)',function(data){
			console.log(data)
			getSelect('parentCode',data.value);
		})
		
		formOn('submit(add)',"/product/insert.do","text",function(data){
			if(data=="B"){	
				layer.msg("添加成功",toClose);	
			}else if(data == "A"){	
				layer.msg("编号重复");	
			}else{
				layer.msg("添加失败");	
			}
		})
		
		
	</script>	

</body>
</html>